<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@include file="/WEB-INF/ibnms/common/easyui.jsp" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>组织信息同步接口列表</title>
    <link href="<%=application.getContextPath()%>/nresources/ued/css/all-src.css" type="text/css" rel="stylesheet" />
    <%@include file="/WEB-INF/ibnms/common/jqgrid.jsp"%>
</head>

<body>
<div class="form-wrapper">
    <div class="form-title">
        <span class="ttcorner"></span>
        <h3>
            <span class="text">组织信息同步接口列表</span>
        </h3>
    </div>
    <div id="role-rel-module-form" class="block02" style="display:none">
        <div class="title-style02">
            <input id="submitBtn" type="button" class="btn-style02" align="middle" value="保存" />
            <input id='returnBtn' type='button' class="btn-style02" value='返回' />
        </div>
        <div style="height:80%">
            <ul id="moduleManageTree" class="ztree" style="width:100%; height:100%;overflow-y:auto;overflow-x:hidden"></ul>
            <div id='loadingmoduleTree' style='display:none;'><img src="<%=application.getContextPath()%>/njs/basd/ztree/css/zTreeStyle/img/loading.gif"/>load....</div>
        </div>
    </div>
    <div id="role-form" class="block02">
        <div class="title-style02">
            <input class="btn-style02" type="button" id="btn-add" value="增加">&nbsp;&nbsp;
            <input class="btn-style02" type="button" id="btn-edit" value="修改">&nbsp;&nbsp;
            <input class="btn-style02" type="button" id="btn-del" value="删除">&nbsp;&nbsp;
        </div>
        <table id="gridTable" width="80%">
        </table>
        <div id="gridPager">
        </div>
        <form name="theForm" method="post" >
            <input type="hidden" name="roleForm.ROLE_ID" value="${roleForm.ROLE_ID}"/>
            <input type="hidden" name="roleForm.PARENT_ID" value="${roleForm.PARENT_ID}"/>
        </form>
    </div>
</div>

</body>
<script type="text/javascript">
var $moduleTreeObj;
var roleId;
function testIF(url){
    $.ajax({
        type:"post",
        dataType:"json",
        url:"<s:url action="testAddUser" />",
        data:{testUrl:url},
        success:function(msg){
           alert(msg)
        }
    })
}

$(function(){
    $("#gridTable").jqGrid({
        url: "webHooksListJson.do",
        datatype: "json",
        mtype: "POST",
        height: "auto",
        autowidth: true,
        colNames:['ID','系统名称', '接口地址','订阅数据类型','操作'],
        colModel:[
            {name:'ID',index:'ID',hidden:true},
            {name:'NAME',index:'NAME',width:'40px'},
            {name:'URL',index:'URL',width:'100px'},
            {name:'TYPE',index:'TYPE',width:'60px',formatter:function(val,o,row){
                var strArray = new Array();
                if(row.USER_EVENDS == 1){
                    strArray.push("用户信息");
                }
                if(row.DEPT_EVENDS == 1){
                    strArray.push("部门信息");
                }
                if(row.ROLE_EVENDS == 1){
                    strArray.push("角色信息");
                }
                if(row.WORKGROUP_EVENDS == 1){
                    strArray.push("工作组信息");
                }
                return strArray.join(",");
            }},
            {name:'TEST',index:'TEST',width:'15px',align:'center',formatter:function(val,o,row){
                return "<input type='button' value='测试' onclick=testIF('"+row.URL+"') title='测试增加用户接口'/>" ;
            }}
        ],
        viewrecords: true,
        rowNum: 15,
        rowList: [10,15,30],
        jsonReader: {
            root: 'rows',
            page: 'page',
            total: 'total',
            records: 'records',
            repeatitems: false,
            subgrid: {
                root: 'rows',
                page: 'page',
                total: 'total',
                records: 'records',
                repeatitems: false
            }
        },
        pager: "#gridPager",
        hidegrid: true,
        multiselect: true,
        beforeRequest:function(){
            var postData = {};
            $(":input[name^='roleForm.']").each(function(){
                postData[$(this).attr("name")] = $(this).val();
            });
            $.extend($("#gridTable").getGridParam("postData"), postData);
        }
    });



    $("#submitBtn").click(function(){
        var checkNodes = $moduleTreeObj.getCheckedNodes(true);
        var cfgNodeIds = "";
        $.each(checkNodes,function(idx,node){
            cfgNodeIds += "#" + $(node).attr("id");
        })
        cfgNodeIds = cfgNodeIds.substring(1);
        $.ajax({
            type:"post",
            dataType:"json",
            url:"saveRoleModel.do",
            data:"theForm.roleID="+roleId+"&theForm.moduleIds="+cfgNodeIds,
            beforeSend:function(){
                $("#submitBtn").val("保存中....");
                $("#submitBtn").attr("disabled","disabled");
            },
            success:function(msg){
                if(msg == 'true'){
                    $("#submitBtn").val("保存");
                    $("#submitBtn").removeAttr("disabled");
                }
            }
        })
    });

    $("#returnBtn").click(function(){
        $("#role-rel-module-form").toggle("slow");
        $("#role-form").toggle("slow");
    });

});


$("#btn-search").click(function(){
    $("#gridTable").trigger("reloadGrid",[{page:1}]);
});

$("#btn-add").click(function(){
    $("form[name='theForm']").attr("action","<s:url action='webHooks' />").submit();
});
$("#btn-del").click(function(){
    var idArr = jQuery("#gridTable").jqGrid('getGridParam','selarrrow');
    if (idArr.length == 0) {
        alert("请先选择要删除的记录!");
        return;
    }

    if(confirm("是否删除所选的记录?")){
        var list = [];
        for (var one in idArr){
            var data = jQuery("#gridTable").jqGrid('getRowData',idArr[one]);
            list.push(data.ID);
        }
        $.ajax({
            type: "POST",
            async: false,
            url: "<s:url action="delWebHooks"/>",
            data:{list:list},
            success: function(data){
                $("#gridTable").trigger('reloadGrid');
                alert("删除成功");
            }
        });
    }
});
$("#btn-edit").click(function() {
    var idArr = jQuery("#gridTable").jqGrid('getGridParam','selarrrow');
    switch (idArr.length) {
        case 0:
            alert("请先选择要修改的记录!");
            break;
        case 1:
            var data = jQuery("#gridTable").jqGrid('getRowData',idArr[0]);
            $("form[name='theForm']").attr("action","<s:url action='webHooks' />?id="+data.ID+"&op=edit").submit();
            break;
        default:
            alert("一次只能修改一条记录!");
    }
});

</script>
</html>
